package com.example.springboothello.service;

import com.example.springboothello.entity.Order;
import com.example.springboothello.listener.MyMulticaster;
import com.example.springboothello.listener.OrderEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;

@Component
public class OrderService implements ApplicationEventPublisherAware {
    private ApplicationEventPublisher eventPublisher ;
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.eventPublisher = applicationEventPublisher ;
    }
    public void save(Order order) {
        this.eventPublisher.publishEvent(new OrderEvent("create oder event", order));
    }




    /*@Bean
    public SimpleApplicationEventMulticaster applicationEventMulticaster() {
        MyMulticaster applicationEventMulticaster = new MyMulticaster();
        applicationEventMulticaster.setTaskExecutor(Executors.newSingleThreadExecutor()) ;
        return applicationEventMulticaster ;
    }*/
}
